﻿using System;
using System.Windows.Forms;

namespace EncodingTools {
    public partial class StringEncodingControl : UserControl {
        public StringEncodingControl() {
            InitializeComponent();

            _encodingTypes.Items.Add(new EncoderItem("Base-64", new Base64Encoder()));
            _encodingTypes.SelectedIndex = 0;
        }

        private EncoderItem SelectedEncoderItem {
            get { return (EncoderItem)_encodingTypes.SelectedItem; }
        }

        private void _encode_Click(object sender, EventArgs e) {
            byte[] ret = SelectedEncoderItem.Encoder.Encode(_source.Data);
            _output.Data = ret;
        }

        private void _decode_Click(object sender, EventArgs e) {
            byte[] ret = SelectedEncoderItem.Encoder.Decode(_source.Data);
            _output.Data = ret;
        }

        public class EncoderItem {
            public string Name { private get; set; }
            public IEncoder Encoder { private set; get; }

            public EncoderItem(string name, IEncoder encoder) {
                Name = name;
                Encoder = encoder;
            }

            public override string ToString() {
                return Name;
            }
        }
    }
}
